﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Web;

namespace ACM
{
    /// <summary>
    /// Summary description for StampViewDoc
    /// </summary>
    public class StampViewDoc : IHttpHandler
    {        

        public void ProcessRequest(HttpContext context)
        {
            string strCon = ConfigurationManager.ConnectionStrings["TMTConnectionString"].ToString();
            int txId = Convert.ToInt16(context.Request.QueryString["txId"]);
            int userId = Convert.ToInt16(context.Request.QueryString["UserID"]);

            int TimeZoneDiff = Convert.ToInt32(ConfigurationManager.AppSettings["TimeZoneDiff"].ToString());
            string qry = "Update acm_tx set attach1_view_date=@now Where id=@id";

            context.Response.ContentType = "text/plain";
            SqlConnection con = new SqlConnection(strCon);
            
            try
            {                
                con.Open();
                SqlCommand cmd = new SqlCommand(qry, con);
                cmd.Parameters.AddWithValue("now", DateTime.Now.AddHours(TimeZoneDiff));
                cmd.Parameters.AddWithValue("id", txId);

                if (cmd.ExecuteNonQuery() > 0)
                    context.Response.Write("success");
                else
                    context.Response.Write("fail");
            }
            catch (Exception)
            {
                context.Response.Write("fail");
            }
            finally
            {
                con.Close();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}